// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyOnionPeelAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyOnionPeelAttributes
//
// Purpose:
//   Attributes for the onion peel operator
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a OnionPeelAttributes.
//
struct OnionPeelAttributesObject
{
    PyObject_HEAD
    OnionPeelAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewOnionPeelAttributes(int);
std::string
PyOnionPeelAttributes_ToString(const OnionPeelAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *adjacencyType_names = "Node, Face";
    switch (atts->GetAdjacencyType())
    {
      case OnionPeelAttributes::Node:
          snprintf(tmpStr, 1000, "%sadjacencyType = %sNode  # %s\n", prefix, prefix, adjacencyType_names);
          str += tmpStr;
          break;
      case OnionPeelAttributes::Face:
          snprintf(tmpStr, 1000, "%sadjacencyType = %sFace  # %s\n", prefix, prefix, adjacencyType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetUseGlobalId())
        snprintf(tmpStr, 1000, "%suseGlobalId = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%suseGlobalId = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scategoryName = \"%s\"\n", prefix, atts->GetCategoryName().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%ssubsetName = \"%s\"\n", prefix, atts->GetSubsetName().c_str());
    str += tmpStr;
    {   const intVector &index = atts->GetIndex();
        snprintf(tmpStr, 1000, "%sindex = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < index.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", index[i]);
            str += tmpStr;
            if(i < index.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetLogical())
        snprintf(tmpStr, 1000, "%slogical = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%slogical = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%srequestedLayer = %d\n", prefix, atts->GetRequestedLayer());
    str += tmpStr;
    const char *seedType_names = "SeedCell, SeedNode";
    switch (atts->GetSeedType())
    {
      case OnionPeelAttributes::SeedCell:
          snprintf(tmpStr, 1000, "%sseedType = %sSeedCell  # %s\n", prefix, prefix, seedType_names);
          str += tmpStr;
          break;
      case OnionPeelAttributes::SeedNode:
          snprintf(tmpStr, 1000, "%sseedType = %sSeedNode  # %s\n", prefix, prefix, seedType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetHonorOriginalMesh())
        snprintf(tmpStr, 1000, "%shonorOriginalMesh = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%shonorOriginalMesh = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
OnionPeelAttributes_Notify(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_SetAdjacencyType(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid adjacencyType value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Node";
        ss << ", Face";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the adjacencyType in the object.
    obj->data->SetAdjacencyType(OnionPeelAttributes::NodeFace(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetAdjacencyType(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetAdjacencyType()));
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetUseGlobalId(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the useGlobalId in the object.
    obj->data->SetUseGlobalId(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetUseGlobalId(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetUseGlobalId()?1L:0L);
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetCategoryName(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the categoryName in the object.
    obj->data->SetCategoryName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetCategoryName(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetCategoryName().c_str());
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetSubsetName(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the subsetName in the object.
    obj->data->SetSubsetName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetSubsetName(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetSubsetName().c_str());
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetIndex(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetIndex() = vec;
    // Mark the index in the object as modified.
    obj->data->SelectIndex();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetIndex(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the index.
    const intVector &index = obj->data->GetIndex();
    PyObject *retval = PyTuple_New(index.size());
    for(size_t i = 0; i < index.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(index[i])));
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetLogical(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the logical in the object.
    obj->data->SetLogical(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetLogical(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLogical()?1L:0L);
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetRequestedLayer(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the requestedLayer in the object.
    obj->data->SetRequestedLayer(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetRequestedLayer(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetRequestedLayer()));
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetSeedType(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid seedType value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " SeedCell";
        ss << ", SeedNode";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the seedType in the object.
    obj->data->SetSeedType(OnionPeelAttributes::SeedIdType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetSeedType(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSeedType()));
    return retval;
}

/*static*/ PyObject *
OnionPeelAttributes_SetHonorOriginalMesh(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the honorOriginalMesh in the object.
    obj->data->SetHonorOriginalMesh(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
OnionPeelAttributes_GetHonorOriginalMesh(PyObject *self, PyObject *args)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetHonorOriginalMesh()?1L:0L);
    return retval;
}



PyMethodDef PyOnionPeelAttributes_methods[ONIONPEELATTRIBUTES_NMETH] = {
    {"Notify", OnionPeelAttributes_Notify, METH_VARARGS},
    {"SetAdjacencyType", OnionPeelAttributes_SetAdjacencyType, METH_VARARGS},
    {"GetAdjacencyType", OnionPeelAttributes_GetAdjacencyType, METH_VARARGS},
    {"SetUseGlobalId", OnionPeelAttributes_SetUseGlobalId, METH_VARARGS},
    {"GetUseGlobalId", OnionPeelAttributes_GetUseGlobalId, METH_VARARGS},
    {"SetCategoryName", OnionPeelAttributes_SetCategoryName, METH_VARARGS},
    {"GetCategoryName", OnionPeelAttributes_GetCategoryName, METH_VARARGS},
    {"SetSubsetName", OnionPeelAttributes_SetSubsetName, METH_VARARGS},
    {"GetSubsetName", OnionPeelAttributes_GetSubsetName, METH_VARARGS},
    {"SetIndex", OnionPeelAttributes_SetIndex, METH_VARARGS},
    {"GetIndex", OnionPeelAttributes_GetIndex, METH_VARARGS},
    {"SetLogical", OnionPeelAttributes_SetLogical, METH_VARARGS},
    {"GetLogical", OnionPeelAttributes_GetLogical, METH_VARARGS},
    {"SetRequestedLayer", OnionPeelAttributes_SetRequestedLayer, METH_VARARGS},
    {"GetRequestedLayer", OnionPeelAttributes_GetRequestedLayer, METH_VARARGS},
    {"SetSeedType", OnionPeelAttributes_SetSeedType, METH_VARARGS},
    {"GetSeedType", OnionPeelAttributes_GetSeedType, METH_VARARGS},
    {"SetHonorOriginalMesh", OnionPeelAttributes_SetHonorOriginalMesh, METH_VARARGS},
    {"GetHonorOriginalMesh", OnionPeelAttributes_GetHonorOriginalMesh, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
OnionPeelAttributes_dealloc(PyObject *v)
{
   OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *OnionPeelAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyOnionPeelAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "adjacencyType") == 0)
        return OnionPeelAttributes_GetAdjacencyType(self, NULL);
    if(strcmp(name, "Node") == 0)
        return PyInt_FromLong(long(OnionPeelAttributes::Node));
    if(strcmp(name, "Face") == 0)
        return PyInt_FromLong(long(OnionPeelAttributes::Face));

    if(strcmp(name, "useGlobalId") == 0)
        return OnionPeelAttributes_GetUseGlobalId(self, NULL);
    if(strcmp(name, "categoryName") == 0)
        return OnionPeelAttributes_GetCategoryName(self, NULL);
    if(strcmp(name, "subsetName") == 0)
        return OnionPeelAttributes_GetSubsetName(self, NULL);
    if(strcmp(name, "index") == 0)
        return OnionPeelAttributes_GetIndex(self, NULL);
    if(strcmp(name, "logical") == 0)
        return OnionPeelAttributes_GetLogical(self, NULL);
    if(strcmp(name, "requestedLayer") == 0)
        return OnionPeelAttributes_GetRequestedLayer(self, NULL);
    if(strcmp(name, "seedType") == 0)
        return OnionPeelAttributes_GetSeedType(self, NULL);
    if(strcmp(name, "SeedCell") == 0)
        return PyInt_FromLong(long(OnionPeelAttributes::SeedCell));
    if(strcmp(name, "SeedNode") == 0)
        return PyInt_FromLong(long(OnionPeelAttributes::SeedNode));

    if(strcmp(name, "honorOriginalMesh") == 0)
        return OnionPeelAttributes_GetHonorOriginalMesh(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyOnionPeelAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyOnionPeelAttributes_methods[i].ml_name),
                PyString_FromString(PyOnionPeelAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyOnionPeelAttributes_methods, self, name);
}

int
PyOnionPeelAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "adjacencyType") == 0)
        obj = OnionPeelAttributes_SetAdjacencyType(self, args);
    else if(strcmp(name, "useGlobalId") == 0)
        obj = OnionPeelAttributes_SetUseGlobalId(self, args);
    else if(strcmp(name, "categoryName") == 0)
        obj = OnionPeelAttributes_SetCategoryName(self, args);
    else if(strcmp(name, "subsetName") == 0)
        obj = OnionPeelAttributes_SetSubsetName(self, args);
    else if(strcmp(name, "index") == 0)
        obj = OnionPeelAttributes_SetIndex(self, args);
    else if(strcmp(name, "logical") == 0)
        obj = OnionPeelAttributes_SetLogical(self, args);
    else if(strcmp(name, "requestedLayer") == 0)
        obj = OnionPeelAttributes_SetRequestedLayer(self, args);
    else if(strcmp(name, "seedType") == 0)
        obj = OnionPeelAttributes_SetSeedType(self, args);
    else if(strcmp(name, "honorOriginalMesh") == 0)
        obj = OnionPeelAttributes_SetHonorOriginalMesh(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
OnionPeelAttributes_print(PyObject *v, FILE *fp, int flags)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)v;
    fprintf(fp, "%s", PyOnionPeelAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
OnionPeelAttributes_str(PyObject *v)
{
    OnionPeelAttributesObject *obj = (OnionPeelAttributesObject *)v;
    return PyString_FromString(PyOnionPeelAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *OnionPeelAttributes_Purpose = "Attributes for the onion peel operator";
#else
static char *OnionPeelAttributes_Purpose = "Attributes for the onion peel operator";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(OnionPeelAttributesType,         \
                  "OnionPeelAttributes",           \
                  OnionPeelAttributesObject,       \
                  OnionPeelAttributes_dealloc,     \
                  OnionPeelAttributes_print,       \
                  PyOnionPeelAttributes_getattr,   \
                  PyOnionPeelAttributes_setattr,   \
                  OnionPeelAttributes_str,         \
                  OnionPeelAttributes_Purpose,     \
                  OnionPeelAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
OnionPeelAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &OnionPeelAttributesType
         || Py_TYPE(other) != &OnionPeelAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    OnionPeelAttributes *a = ((OnionPeelAttributesObject *)self)->data;
    OnionPeelAttributes *b = ((OnionPeelAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static OnionPeelAttributes *defaultAtts = 0;
static OnionPeelAttributes *currentAtts = 0;

static PyObject *
NewOnionPeelAttributes(int useCurrent)
{
    OnionPeelAttributesObject *newObject;
    newObject = PyObject_NEW(OnionPeelAttributesObject, &OnionPeelAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new OnionPeelAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new OnionPeelAttributes(*defaultAtts);
    else
        newObject->data = new OnionPeelAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapOnionPeelAttributes(const OnionPeelAttributes *attr)
{
    OnionPeelAttributesObject *newObject;
    newObject = PyObject_NEW(OnionPeelAttributesObject, &OnionPeelAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (OnionPeelAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
OnionPeelAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewOnionPeelAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef OnionPeelAttributesMethods[] = {
    {"OnionPeelAttributes", OnionPeelAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *OnionPeelAttributesObserver = 0;

std::string
PyOnionPeelAttributes_GetLogString()
{
    std::string s("OnionPeelAtts = OnionPeelAttributes()\n");
    if(currentAtts != 0)
        s += PyOnionPeelAttributes_ToString(currentAtts, "OnionPeelAtts.", true);
    return s;
}

static void
PyOnionPeelAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("OnionPeelAtts = OnionPeelAttributes()\n");
        s += PyOnionPeelAttributes_ToString(currentAtts, "OnionPeelAtts.", true);
        cb(s);
    }
}

void
PyOnionPeelAttributes_StartUp(OnionPeelAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyOnionPeelAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(OnionPeelAttributesObserver == 0)
    {
        OnionPeelAttributesObserver = new ObserverToCallback(subj,
            PyOnionPeelAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyOnionPeelAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete OnionPeelAttributesObserver;
    OnionPeelAttributesObserver = 0;
}

PyMethodDef *
PyOnionPeelAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return OnionPeelAttributesMethods;
}

bool
PyOnionPeelAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &OnionPeelAttributesType);
}

OnionPeelAttributes *
PyOnionPeelAttributes_FromPyObject(PyObject *obj)
{
    OnionPeelAttributesObject *obj2 = (OnionPeelAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyOnionPeelAttributes_New()
{
    return NewOnionPeelAttributes(0);
}

PyObject *
PyOnionPeelAttributes_Wrap(const OnionPeelAttributes *attr)
{
    return WrapOnionPeelAttributes(attr);
}

void
PyOnionPeelAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    OnionPeelAttributesObject *obj2 = (OnionPeelAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyOnionPeelAttributes_SetDefaults(const OnionPeelAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new OnionPeelAttributes(*atts);
}

